package dao;

import entity.Meeting;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class GetMeetingInfo {
    public static ArrayList<Meeting> getParticipate(String id){
        ArrayList<Meeting> res=new ArrayList<>();
        String sql="select id,name,introduce,room_id,begin_time,end_time,manager,code from meeting where id in( select meeting_id from attendence where account_id =?)";
        try {
            Connection conn=DataBaseConnect.getConnection();
            PreparedStatement pstmt=conn.prepareStatement(sql);
            pstmt.setString(1,id);
            ResultSet rs=pstmt.executeQuery();
            while (rs.next()){
                res.add(new Meeting(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),
                        rs.getTimestamp(5).toLocalDateTime(),rs.getTimestamp(6).toLocalDateTime(),rs.getString(8)));
            }
        }catch (Exception e){
            System.out.println("获取会议信息error");
            e.printStackTrace();
        }
        return res;
    }
    public static ArrayList<Meeting> getManage(String id){
        ArrayList<Meeting> res=new ArrayList<>();
        String sql="select id,name,introduce,room_id,begin_time,end_time,manager,code from meeting where manager =?";
        try {
            Connection conn=DataBaseConnect.getConnection();
            PreparedStatement pstmt=conn.prepareStatement(sql);
            pstmt.setString(1,id);
            ResultSet rs=pstmt.executeQuery();
            while (rs.next()){
                res.add(new Meeting(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),
                        rs.getTimestamp(5).toLocalDateTime(),rs.getTimestamp(6).toLocalDateTime(),rs.getString(8)));
            }
        }catch (Exception e){
            System.out.println("获取会议信息error");
            e.printStackTrace();
        }
        return res;
    }
}
